
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>文本处理服务 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="string --- 常见的字符串操作" href="string.html" />
    <link rel="prev" title="内置异常" href="exceptions.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/text.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="string.html" title="string --- 常见的字符串操作"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="exceptions.html" title="内置异常"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python 标准库</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="text-processing-services">
<span id="textservices"></span><span id="stringservices"></span><h1>文本处理服务<a class="headerlink" href="#text-processing-services" title="永久链接至标题">¶</a></h1>
<p>本章介绍的模块提供了广泛的字符串操作和其他文本处理服务。</p>
<p>在 <a class="reference internal" href="binary.html#binaryservices"><span class="std std-ref">二进制数据服务</span></a> 之下描述的  <a class="reference internal" href="codecs.html#module-codecs" title="codecs: Encode and decode data and streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">codecs</span></code></a> 模块也与文本处理高度相关。 此外也请参阅 Python 内置字符串类型的文档 <a class="reference internal" href="stdtypes.html#textseq"><span class="std std-ref">文本序列类型 --- str</span></a>。</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="string.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">string</span></code> --- 常见的字符串操作</a><ul>
<li class="toctree-l2"><a class="reference internal" href="string.html#string-constants">字符串常量</a></li>
<li class="toctree-l2"><a class="reference internal" href="string.html#custom-string-formatting">自定义字符串格式化</a></li>
<li class="toctree-l2"><a class="reference internal" href="string.html#format-string-syntax">格式字符串语法</a><ul>
<li class="toctree-l3"><a class="reference internal" href="string.html#format-specification-mini-language">格式规格迷你语言</a></li>
<li class="toctree-l3"><a class="reference internal" href="string.html#format-examples">格式示例</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="string.html#template-strings">模板字符串</a></li>
<li class="toctree-l2"><a class="reference internal" href="string.html#helper-functions">辅助函数</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="re.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code> --- 正则表达式操作</a><ul>
<li class="toctree-l2"><a class="reference internal" href="re.html#regular-expression-syntax">正则表达式语法</a></li>
<li class="toctree-l2"><a class="reference internal" href="re.html#module-contents">模块内容</a></li>
<li class="toctree-l2"><a class="reference internal" href="re.html#regular-expression-objects">正则表达式对象 （正则对象）</a></li>
<li class="toctree-l2"><a class="reference internal" href="re.html#match-objects">匹配对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="re.html#regular-expression-examples">正则表达式例子</a><ul>
<li class="toctree-l3"><a class="reference internal" href="re.html#checking-for-a-pair">检查对子</a></li>
<li class="toctree-l3"><a class="reference internal" href="re.html#simulating-scanf">模拟 scanf()</a></li>
<li class="toctree-l3"><a class="reference internal" href="re.html#search-vs-match">search() vs. match()</a></li>
<li class="toctree-l3"><a class="reference internal" href="re.html#making-a-phonebook">建立一个电话本</a></li>
<li class="toctree-l3"><a class="reference internal" href="re.html#text-munging">文字整理</a></li>
<li class="toctree-l3"><a class="reference internal" href="re.html#finding-all-adverbs">找到所有副词</a></li>
<li class="toctree-l3"><a class="reference internal" href="re.html#finding-all-adverbs-and-their-positions">找到所有副词和位置</a></li>
<li class="toctree-l3"><a class="reference internal" href="re.html#raw-string-notation">原始字符记法</a></li>
<li class="toctree-l3"><a class="reference internal" href="re.html#writing-a-tokenizer">写一个词法分析器</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="difflib.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">difflib</span></code> --- 计算差异的辅助工具</a><ul>
<li class="toctree-l2"><a class="reference internal" href="difflib.html#sequencematcher-objects">SequenceMatcher 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="difflib.html#sequencematcher-examples">SequenceMatcher 的示例</a></li>
<li class="toctree-l2"><a class="reference internal" href="difflib.html#differ-objects">Differ 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="difflib.html#differ-example">Differ 示例</a></li>
<li class="toctree-l2"><a class="reference internal" href="difflib.html#a-command-line-interface-to-difflib">difflib 的命令行接口</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="textwrap.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">textwrap</span></code> --- 文本自动换行与填充</a></li>
<li class="toctree-l1"><a class="reference internal" href="unicodedata.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unicodedata</span></code> --- Unicode 数据库</a></li>
<li class="toctree-l1"><a class="reference internal" href="stringprep.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringprep</span></code> --- 因特网字符串预备</a></li>
<li class="toctree-l1"><a class="reference internal" href="readline.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> --- GNU readline 接口</a><ul>
<li class="toctree-l2"><a class="reference internal" href="readline.html#init-file">初始化文件</a></li>
<li class="toctree-l2"><a class="reference internal" href="readline.html#line-buffer">行缓冲区</a></li>
<li class="toctree-l2"><a class="reference internal" href="readline.html#history-file">历史文件</a></li>
<li class="toctree-l2"><a class="reference internal" href="readline.html#history-list">历史列表</a></li>
<li class="toctree-l2"><a class="reference internal" href="readline.html#startup-hooks">启动钩子</a></li>
<li class="toctree-l2"><a class="reference internal" href="readline.html#completion">Completion</a></li>
<li class="toctree-l2"><a class="reference internal" href="readline.html#example">示例</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="rlcompleter.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">rlcompleter</span></code> --- GNU readline 的补全函数</a><ul>
<li class="toctree-l2"><a class="reference internal" href="rlcompleter.html#completer-objects">Completer 对象</a></li>
</ul>
</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="exceptions.html"
                        title="上一章">内置异常</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="string.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">string</span></code> --- 常见的字符串操作</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/text.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="string.html" title="string --- 常见的字符串操作"
             >下一页</a> |</li>
        <li class="right" >
          <a href="exceptions.html" title="内置异常"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>